#!/usr/bin/env python

# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import subprocess
import sys

_GYP_REVISION = '1344'
_GYP_FETCH_URL = 'https://gyp.googlecode.com/svn/trunk@' + _GYP_REVISION

def _fetch_gyp():
  gyp_dir = os.path.join('third_party', 'gyp')
  if not os.path.exists(gyp_dir):
    retcode = subprocess.call(['svn', 'checkout', _GYP_FETCH_URL, gyp_dir])
    if retcode < 0:
      raise "Couldn't fetch gyp"
  # TODO(bashi): Check revision, etc
  sys.path.insert(0, os.path.abspath(os.path.join(gyp_dir, 'pylib')))

def main():
  script_dir = os.path.abspath(os.path.dirname(__file__))
  os.chdir(script_dir)
  _fetch_gyp()
  import gyp

  args = []
  args.extend(['--depth', '.'])
  args.extend(sys.argv[1:])
  args.append(os.path.join(script_dir, 'ots-standalone.gyp'))
  sys.exit(gyp.main(args))

if __name__ == '__main__':
  main()
